const favorFilter = (item: any, setsearchValue: any, setDatabasekeywords: any) => {
  setsearchValue((prevItems: any) => {
    return { ...prevItems, filters: { pca: [], polymerize: [], date: [], park: [], time: [], industry: [], national_economy_classification: [] } }
  })

  item.filters.items.forEach((item: any) => {
    if (
      item.type === 'pca' ||
      item.type === 'polymerize' ||
      item.type === 'park' ||
      item.type === 'industry' ||
      item.type === 'national_economy_classification'
    ) {
      setsearchValue((prevItems: any) => {
        prevItems.filters[item.type] = [...prevItems.filters[item.type], item]
        return { ...prevItems }
      })
    } else if (item.type === 'date' || item.type === 'time') {
      setsearchValue((prevItems: any) => {
        prevItems.filters[item.type] = [...prevItems.filters[item.type], item]
        return { ...prevItems }
      })
    }
  })

  if (item.filters.keywords) setDatabasekeywords(item.filters.keywords)
}

export { favorFilter }
